home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / GraphicViewers / pCD / Source / PhotoWinProcs.m < prev    next >
Text File  |  1993-01-16  |  2KB  |  89 lines

  1. /*
  2.    This creates the window that displays an individual Photo image.
  3.    It is also the delegate for that window.
  4. */
  5.  
  6. #import "PhotoWinProcs.h"
  7. #import "ImageView.h"
  8.  
  9. @implementation PhotoWinProcs
  10.  
  11. - (enum _NXWindowDepth)getDepthOfNewWindows
  12. {
  13.     return depthOfNewWindows;
  14. }
  15.  
  16.  
  17. - setDepthOfNewWindows:(enum _NXWindowDepth)windowDepth
  18. {
  19.     depthOfNewWindows = windowDepth;
  20.     return self;
  21. }
  22.  
  23.  
  24. - displayImage:(id)theImage withName:(char *)imName atResolution:(int)imRes
  25. {
  26.     Window     *win;
  27.     int        pixHigh, pixWide;
  28.     NXRect   imRect = {{10.0, 10.0}, {0.0, 0.0}};
  29.     
  30.     pixHigh = [theImage pixelsHigh];
  31.     pixWide = [theImage pixelsWide];
  32.     [theImage getSize:&imRect.size];    // for reference purposes
  33.  
  34.     if ( imRes >= 72 ) {
  35.     /* turn image into the requested resolution */
  36.     imRect.size.width  = ( pixWide * 72.0) / (float)imRes;
  37.     imRect.size.height = ( pixHigh * 72.0) / (float)imRes;
  38.     [theImage setSize:&imRect.size];
  39.     }
  40.  
  41.     win = [[Window alloc] initContent:&imRect
  42.         style:NX_TITLEDSTYLE
  43.         backing:NX_BUFFERED
  44.         buttonMask:NX_CLOSEBUTTONMASK|NX_MINIATURIZEBUTTONMASK
  45.         defer: YES];
  46.     [win setDelegate:self];
  47.     [win setTitleAsFilename:imName];
  48.  
  49.     /* we have to set the depth here, or cut & paste operations may not
  50.        keep all the desired information (particularly if running this
  51.        on a greyscale station).
  52.     */
  53.     [win setDepthLimit:depthOfNewWindows];
  54.     [win setContentView:[[ImageView alloc] initForImage:theImage :&imRect]];
  55.     [win makeKeyAndOrderFront:self];
  56.  
  57.     return self;
  58. }
  59.  
  60. - windowWillClose:sender
  61. {
  62.     id        imageID;
  63. //    NXBitmapImageRep  *imageBitmap;
  64.     u_char    *rgb[5];
  65.     
  66.     /*  have to free up the image that the window is displaying,
  67.         and due to the way we got the bitmap for that image, the
  68.     RGB data planes have to be found and freed too */
  69.     imageID = [[sender contentView] image];
  70.     
  71.     /* the following should be done via a call to freeDataPlanes in
  72.        photoCD_Rdr, but at the moment it isn't... */
  73.     if ( [imageID isPlanar] ) {
  74.     /* a rather sleezy way to distinguish between images that
  75.        were read in and images which were cut/pasted in...  */
  76.     [imageID getDataPlanes:rgb];
  77.     if ( rgb[0] ) free( rgb[0] );
  78.     if ( rgb[1] ) free( rgb[1] );
  79.     if ( rgb[2] ) free( rgb[2] );
  80.     }
  81.     
  82.     [imageID free];
  83.     
  84.     return self;
  85. }
  86.  
  87.  
  88. @end
  89.